/*
 *  $TEAM_NAME Space Trader
 */
package presenters;

import models.Game;

import views.HubPanel;
import views.NewGamePanel;
import views.TitlePanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;


/**
 * Handles the presentation of the title screen
 * @author bradley
 * @version 1.0
 */
public class TitlePresenter extends Presenter<TitlePanel> implements ActionListener {
	/**
	 * field
	 */
	private final TitlePanel titlePanel;

    /**
     * Default constructor
     * @param titlePanel - the view to present
     */
	public TitlePresenter(TitlePanel titlePanel) {
	    this.titlePanel = titlePanel;
	    this.titlePanel.addActionListener(this);
	    super.setView(this.titlePanel);
	}
	
	/**
	 * Fired when an action was performed on the new game vie
	 * @param e - the event that was performed
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		final Object source = e.getSource();

		if (source instanceof JButton) {
		    final JButton button = (JButton) source;

            if (button.getText().equals("New")) {
                // Create a new game
                final NewGamePresenter presenter = new 
                		NewGamePresenter(new NewGamePanel());
                present(presenter);
            } else if ("Load".equals(button.getText())) {
                // Load a game
            	final Game game = Game.load();
            	final HubPresenter hub = new HubPresenter(
            			game, new HubPanel(game, this.getFrame()));
            	present(hub);
            }
        }
    }
	
	/**
	 * to string
	 * @return string
	 */
	@Override
	public String toString() {
		return "";
	}
}
